package com.wolfking.controller;

import com.wolfking.spi.SpiApplicationContext;
import com.wolfking.demo.spi.HelloService;
import com.wolfking.demo.spi.Nation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *
 * @author 赵伟伟(wolfking)
 * created on 2019-10-17 19:31
 */
@Order(-100)
@Slf4j
@RestController
@RequestMapping("/spi")
@Api(value = "spi", tags = "spi代理")
public class SpiController {
    @Autowired
    @SuppressWarnings("all")
    private HelloService helloService;

    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    @SneakyThrows
    @GetMapping("/hello")
    @ApiOperation(value = "三种语言的hello")
    public Object hello(@RequestParam("code") Nation code) {
        try {
            return helloService.choice(code).sayHello("西门庆");
        } catch (Exception e) {
            log.error("a", e);
            SpiApplicationContext.setSpiCode(code.name());
            return helloService.sayHello("西门庆");
        }
    }
}
